package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Coupon;
import com.cskaoyan.bean.CouponUserListRequestVo;
import com.cskaoyan.bean.CouponResponseVo;
import com.cskaoyan.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("admin/coupon")
public class CouponController {
    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    public BaseRespVo list(@ModelAttribute CouponResponseVo couponResponseVo){
        Map<String, Object> baseData = couponService.CouponList(couponResponseVo);
        return BaseRespVo.ok(baseData);
    }

    @RequestMapping("create")
    public BaseRespVo addCouponList(@RequestBody Coupon coupon) {
        Coupon couponNew = couponService.addCoupon(coupon);
        return BaseRespVo.ok(couponNew);
    }


    /**
     * @param id
     * @return
     * 显示优惠券详情
     */
    @RequestMapping("read")
    public BaseRespVo readCoupon(@RequestParam("id") Integer id) {
        Coupon coupon = couponService.readCouponById(id);
        return BaseRespVo.ok(coupon);
    }

    /**
     * @param requestVo
     * @return
     * 显示持有该优惠券的用户的信息
     */
    @RequestMapping("listuser")
    public BaseRespVo getCouponUsers(@ModelAttribute CouponUserListRequestVo requestVo) {
        Map<String, Object> resultMap = couponService.getCouponUsers(requestVo);
        return BaseRespVo.ok(resultMap);
    }


    /**
     * @param coupon
     * @return
     * 修改优惠券信息
     */
    @RequestMapping("update")
    public BaseRespVo updateCoupon(@RequestBody Coupon coupon) {
        Coupon couponNew = couponService.updateCoupon(coupon);
        return BaseRespVo.ok(couponNew);
    }

    /**
     * @param coupon
     * @return
     * 修改优惠券信息
     */
    @RequestMapping("delete")
    public BaseRespVo deleteCoupon(@RequestBody Coupon coupon) {
        couponService.deleteCoupon(coupon);
        return BaseRespVo.ok();
    }
}
